package api

import (
	"cloud_android_backend/api/application"
	"cloud_android_backend/api/instance"
	"cloud_android_backend/api/login"
	"cloud_android_backend/api/machines"
	"cloud_android_backend/api/material"
	"cloud_android_backend/api/orders"
	"cloud_android_backend/api/payment"
	"cloud_android_backend/api/products"
	"cloud_android_backend/api/proxy"
	"cloud_android_backend/api/user"

	"net/http"

	"github.com/gin-gonic/gin"
	"modules.tenxcloud.com/common/server"
	"modules.tenxcloud.com/common/utility/success"
)

var (
	Application = server.Application
	//APIGroup    = "/admin/api"
	//APIGroupV2   = "/api/v2"
	swaggerGroup = "/swagger/*any"
	ApiGroup1    = "/api/v1"
)

type HttpResponseFormat struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

// 成功响应
func SuccessResponse(data interface{}) HttpResponseFormat {
	return HttpResponseFormat{Code: 200, Msg: "success", Data: data}
}

// 错误响应
func ErrorResponse(Msg string) (int, HttpResponseFormat) {
	return http.StatusInternalServerError, HttpResponseFormat{Code: 500, Msg: Msg, Data: ""}
}
func init() {

	// 根路由处理
	Application.GET("/", func(context *gin.Context) {
		context.JSON(success.OK("cloud android backend service is running"))
	})
	// 路由组注册
	// TODO: adding authorization and audit middleware
	apiv1 := Application.Group(ApiGroup1)
	//apiv2 := Application.Group(ApiGroup1)
	// 注册各模块路由
	login.Register(apiv1)
	//role.Register(apiv1)
	application.Register(apiv1)
	orders.Register(apiv1)
	user.Register(apiv1)
	machines.Register(apiv1)
	instance.Register(apiv1)
	products.Register(apiv1)
	payment.Register(apiv1)
	material.Register(apiv1)
	proxy.Register(apiv1)
	//application.Register2(apiv2)
	// debug mode // 调试模式下启用Swagger
	//if config.RunMode() == "debug" {
	//	//docs.SwaggerInfo.BasePath = APIGroup
	//	Application.GET(swaggerGroup, gs.WrapHandler(swaggerFiles.Handler))
	//}

	//product.Register(apiv1)
	//cloud2.Register(Application.Group(APIGroupV2))
}
